package cc.yiueil.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class UserEntity implements UserDetails {
    private Long id;
    private String guid;
    private String userName;
    private String loginName;
    private String password;
    private String phoneNumber;
    private String email;
    private String avatarUrl;
    private String signature;
    private String state;
    private Long createUserId;
    private LocalDateTime createTime;
    private LocalDateTime modifyTime;
    private String extendProperty1;
    private String extendProperty2;
    private String extendProperty3;
    private String extendProperty4;

    private List<String> functionRightName;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
        for (String rightName : functionRightName) {
            authorities.add(new SimpleGrantedAuthority(rightName));
        }
        return authorities;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }
}
